namespace CIS.Customer
{
    using CISLib;
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class CustomerBasicInfoPage : Page
    {
        protected Button btnCustomerProfile;
        protected Button cancelSaveBtn;
        protected DropDownList catDdl;
        protected DropDownList companyDdl;
        protected TextBox customerNameTxb;
        protected Button DelBtn;
        protected TextBox departTxb;
        protected TextBox EmailTxb;
        protected DropDownList genderDdl;
        protected Image iBtnCustomer;
        protected ImageButton iBtnGray0;
        protected ImageButton iBtnOrange1;
        protected ImageButton iBtnOrange2;
        protected ImageButton iBtnOrange3;
        protected ImageButton iBtnOrange4;
        protected ImageButton iBtnOrange5;
        protected ImageButton iBtnOrange6;
        protected ImageButton iBtnOrange7;
        protected ImageButton iBtnOrange8;
        protected Label lbCat;
        protected Label lbCompany;
        protected Label lbCustomerName;
        protected Label lbDepart;
        protected Label lbEditerName;
        protected Label lbGender;
        protected Label lbLevel;
        protected Label lbMail;
        protected Label lbMailAdd;
        protected Label lbProduct;
        protected Label lbRegion;
        protected Label lbSaveMsg;
        protected Label lbStrLevel1;
        protected Label lbStrLevel2;
        protected Label lbStrLevel22;
        protected Label lbStrLevel3;
        protected Label lbStrLevel4;
        protected Label lbStrLevel5;
        protected Label lbSureMsg;
        protected Label lbTitle;
        protected Label lbType;
        protected DropDownList levelDdl;
        protected TextBox MailAddTxb;
        protected UserPrincipal Principal = null;
        protected DropDownList ProductDdl;
        protected ListBox ProductLB;
        protected DropDownList regionDdl;
        protected RegularExpressionValidator RegularExpressionValidatorEmail;
        protected RequiredFieldValidator RequiredFieldValidatorName;
        protected Button saveBtn;
        protected Button sureSaveBtn;
        protected TextBox titleTxb;
        protected Button TypeAddBtn;
        protected DropDownList TypeDdl;

        private void btnCustomerProfile_Click(object sender, EventArgs e)
        {
            Guid customerId = (Guid) this.Page.Session["CustomerId"];
            base.Response.Write("<script>window.open('CustomerProfile.aspx?CustomerId=" + customerId + "')</script>");
        }

        private void cancelSaveBtn_Click(object sender, EventArgs e)
        {
            this.saveBtn.Visible = true;
            this.sureSaveBtn.Visible = false;
            this.cancelSaveBtn.Visible = false;
            this.InitPage();
            this.customerNameTxb.Text = "";
            this.titleTxb.Text = "";
            this.departTxb.Text = "";
            this.lbSureMsg.Text = "";
        }

        private void companyDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            Company com = ManageCompany.GetCompanyViaId(new Guid(this.companyDdl.SelectedValue));
            this.MailAddTxb.Text = com.CompanyAdd + " " + com.CompanyZip;
            this.SetInfoTypeDdl(this.catDdl, com.CATtId.ToString());
            this.SetInfoTypeDdl(this.regionDdl, com.RegionId.ToString());
        }

        private void DelBtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.ProductLB.Items.Remove(this.ProductLB.Items[this.ProductLB.SelectedIndex]);
            }
            catch
            {
            }
        }

        private void FillPage()
        {
            try
            {
                string language = this.Session["language"].ToString();
                Guid customerId = new Guid(base.Request.QueryString["CustomerId"].ToString());
                CustomerBasicInfo customerBasicInfo = ManageCustomer.GetCustomerBasicInfoViaId(customerId);
                Product[] productEdit = ManageProduct.GetProductAryViaId(customerId);
                for (int i = 0; i < productEdit.Length; i++)
                {
                    ListItem tmpListItem = new ListItem();
                    switch (language)
                    {
                        case "cn":
                            tmpListItem.Text = productEdit[i].ProductNameCn;
                            break;

                        case "en":
                            tmpListItem.Text = productEdit[i].ProductNameEn;
                            break;
                    }
                    tmpListItem.Value = productEdit[i].ProductId.ToString();
                    this.ProductLB.Items.Add(tmpListItem);
                }
                this.EmailTxb.Text = customerBasicInfo.CustomerEmail;
                this.customerNameTxb.Text = customerBasicInfo.Name;
                this.titleTxb.Text = customerBasicInfo.Title;
                this.departTxb.Text = customerBasicInfo.Depart;
                this.MailAddTxb.Text = customerBasicInfo.MailAdd;
                this.SetInfoTypeDdl(this.genderDdl, customerBasicInfo.Gender);
                this.SetInfoTypeDdl(this.levelDdl, customerBasicInfo.Level.ToString());
                this.SetInfoTypeDdl(this.companyDdl, customerBasicInfo.CompanyId.ToString());
                this.SetInfoTypeDdl(this.regionDdl, customerBasicInfo.RegionId.ToString());
                this.SetInfoTypeDdl(this.catDdl, customerBasicInfo.CatId.ToString());
                this.SetInfoTypeDdl(this.TypeDdl, customerBasicInfo.CustomerDefId.ToString());
                this.Page.Session.Add("CustomerId", customerId);
                this.lbEditerName.Text = ManageUser.GetUserViaId(customerBasicInfo.UserId).LoginName;
                if ((this.Principal.SysUser.IsAdmin <= 0) && !ManageSystemConfig.IsThisCustomerMaster(this.Principal.SysUser.UserId, customerId))
                {
                    this.customerNameTxb.ReadOnly = true;
                    this.titleTxb.ReadOnly = true;
                    this.departTxb.ReadOnly = true;
                    this.EmailTxb.ReadOnly = true;
                    this.saveBtn.Visible = false;
                    this.TypeAddBtn.Visible = false;
                    this.DelBtn.Visible = false;
                    this.ProductDdl.Visible = false;
                }
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange1_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoPersonalPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange2_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoPreferencePage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange3_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoHealthCostumePage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange4_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoTravelPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange5_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoStudyPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange6_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoWorkPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange7_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoFamilyPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange8_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                Guid customerId = (Guid) this.Page.Session["CustomerId"];
                base.Response.Redirect("~/CIS/Customer/CustomerInfoOtherPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void InitializeComponent()
        {
            this.iBtnOrange1.Click += new ImageClickEventHandler(this.iBtnOrange1_Click);
            this.iBtnOrange2.Click += new ImageClickEventHandler(this.iBtnOrange2_Click);
            this.iBtnOrange3.Click += new ImageClickEventHandler(this.iBtnOrange3_Click);
            this.iBtnOrange4.Click += new ImageClickEventHandler(this.iBtnOrange4_Click);
            this.iBtnOrange5.Click += new ImageClickEventHandler(this.iBtnOrange5_Click);
            this.iBtnOrange6.Click += new ImageClickEventHandler(this.iBtnOrange6_Click);
            this.iBtnOrange7.Click += new ImageClickEventHandler(this.iBtnOrange7_Click);
            this.iBtnOrange8.Click += new ImageClickEventHandler(this.iBtnOrange8_Click);
            this.saveBtn.Click += new EventHandler(this.saveBtn_Click);
            this.sureSaveBtn.Click += new EventHandler(this.sureSaveBtn_Click);
            this.cancelSaveBtn.Click += new EventHandler(this.cancelSaveBtn_Click);
            this.btnCustomerProfile.Click += new EventHandler(this.btnCustomerProfile_Click);
            this.companyDdl.SelectedIndexChanged += new EventHandler(this.companyDdl_SelectedIndexChanged);
            this.TypeAddBtn.Click += new EventHandler(this.TypeAddBtn_Click);
            this.DelBtn.Click += new EventHandler(this.DelBtn_Click);
            base.Load += new EventHandler(this.Page_Load);
        }

        private void InitPage()
        {
            this.SetFromImage();
            this.SetFrom();
            Province[] provinceAry = this.Principal.Province;
            for (int i = 0; i < provinceAry.Length; i++)
            {
                ListItem tmpItem = new ListItem();
                tmpItem.Text = provinceAry[i].ProvinceName;
                tmpItem.Value = provinceAry[i].ProvinceId.ToString();
                this.regionDdl.Items.Add(tmpItem);
            }
            Cat[] catAry = this.Principal.OwnCat;
            for (int i = 0; i < catAry.Length; i++)
            {
                ListItem tmpItem = new ListItem();
                tmpItem.Text = catAry[i].CatName;
                tmpItem.Value = catAry[i].CatId.ToString();
                this.catDdl.Items.Add(tmpItem);
            }
            this.genderDdl.Items.Clear();
            ListItem nullItem = new ListItem();
            nullItem.Text = "";
            ListItem maleItem = new ListItem();
            maleItem.Text = "男";
            ListItem femaleItem = new ListItem();
            femaleItem.Text = "女";
            this.genderDdl.Items.Add(nullItem);
            this.genderDdl.Items.Add(maleItem);
            this.genderDdl.Items.Add(femaleItem);
            this.levelDdl.Items.Clear();
            ListItem blankItem = new ListItem();
            blankItem.Text = string.Empty;
            blankItem.Value = "0";
            this.levelDdl.Items.Add(blankItem);
            for (int i = 1; i <= 5; i++)
            {
                string tmpStr = "Level " + i.ToString();
                ListItem tmpItem = new ListItem();
                tmpItem.Text = tmpStr;
                tmpItem.Value = i.ToString();
                this.levelDdl.Items.Add(tmpItem);
            }
            this.companyDdl.Items.Clear();
            Area[] areaAry = this.Principal.OwnArea;
            DataTable dataTable = new DataTable();
            int y = 0;
            for (int i = 0; i < areaAry.Length; i++)
            {
                for (int j = 0; j < catAry.Length; j++)
                {
                    for (int x = 0; x < provinceAry.Length; x++)
                    {
                        DataTable dt = ManageCompany.GetCompany(catAry[j].CatId, provinceAry[x].ProvinceId, areaAry[i].AreaId).Tables[0];
                        if (y == 0)
                        {
                            dataTable = dt.Clone();
                            y++;
                        }
                        foreach (DataRow tmpRow in dt.Rows)
                        {
                            dataTable.ImportRow(tmpRow);
                        }
                    }
                }
            }
            this.companyDdl.DataSource = dataTable;
            this.companyDdl.DataTextField = "CompanyName";
            this.companyDdl.DataValueField = "CompanyId";
            this.companyDdl.DataBind();
            this.sureSaveBtn.Visible = false;
            this.cancelSaveBtn.Visible = false;
            string language = this.Session["language"].ToString();
            switch (language)
            {
                case "cn":
                    if (this.Principal.OwnArea.Length > 1)
                    {
                        this.TypeDdl.DataSource = ManageCustomerDef.GetCustomerDef();
                        this.TypeDdl.DataTextField = "DefName";
                        this.TypeDdl.DataValueField = "DefId";
                    }
                    else if (this.Principal.OwnArea.Length == 1)
                    {
                        this.TypeDdl.DataSource = ManageCustomerDef.GetCustomerDef(this.Principal.OwnArea[0].AreaId);
                        this.TypeDdl.DataTextField = "DefName";
                        this.TypeDdl.DataValueField = "DefId";
                    }
                    break;

                case "en":
                    if (this.Principal.OwnArea.Length > 1)
                    {
                        this.TypeDdl.DataSource = ManageCustomerDef.GetCustomerDef();
                        this.TypeDdl.DataTextField = "DefNameEn";
                        this.TypeDdl.DataValueField = "DefId";
                    }
                    else if (this.Principal.OwnArea.Length == 1)
                    {
                        this.TypeDdl.DataSource = ManageCustomerDef.GetCustomerDef(this.Principal.OwnArea[0].AreaId);
                        this.TypeDdl.DataTextField = "DefNameEn";
                        this.TypeDdl.DataValueField = "DefId";
                    }
                    break;
            }
            this.TypeDdl.DataBind();
            this.ProductDdl.Items.Clear();
            this.ProductDdl.DataSource = ManageProduct.GetProduct();
            switch (language)
            {
                case "cn":
                    this.ProductDdl.DataTextField = "ProductNameCn";
                    this.ProductDdl.DataValueField = "ProductId";
                    break;

                case "en":
                    this.ProductDdl.DataTextField = "ProductNameEn";
                    this.ProductDdl.DataValueField = "ProductId";
                    break;
            }
            this.ProductDdl.DataBind();
            try
            {
                Company com = ManageCompany.GetCompanyViaId(new Guid(this.companyDdl.SelectedValue));
                this.MailAddTxb.Text = com.CompanyAdd + " " + com.CompanyZip;
            }
            catch
            {
            }
        }

        private bool IsExistItem(ListItem tmpItem, ListBox tmpList)
        {
            for (int i = 0; i < tmpList.Items.Count; i++)
            {
                if (tmpItem.Value == tmpList.Items[i].Value)
                {
                    return true;
                }
            }
            return false;
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
            this.Principal = this.Context.User as UserPrincipal;
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.SelectAuth();
            }
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (!this.ValidateCustomerCompany(new Guid(this.companyDdl.SelectedValue), new Guid(this.regionDdl.SelectedValue), new Guid(this.catDdl.SelectedValue)))
                {
                    this.lbSaveMsg.Text = "客户公司和所设区域不符！";
                    this.lbSureMsg.Text = "";
                }
                else
                {
                    string strEmailTxb = this.EmailTxb.Text.Trim();
                    string strMailAddTxb = this.MailAddTxb.Text.Trim();
                    string strName = this.customerNameTxb.Text.Trim();
                    string strGender = this.genderDdl.SelectedItem.Text.Trim();
                    string strTitle = this.titleTxb.Text.Trim();
                    int iLevel = Convert.ToInt32(this.levelDdl.SelectedItem.Value);
                    Guid companyId = new Guid(this.companyDdl.SelectedItem.Value);
                    string strDepart = this.departTxb.Text.Trim();
                    Guid[] productId = new Guid[this.ProductLB.Items.Count];
                    for (int i = 0; i < this.ProductLB.Items.Count; i++)
                    {
                        productId[i] = new Guid(this.ProductLB.Items[i].Value);
                    }
                    if (base.Request.QueryString["IsModify"].ToString() == "True")
                    {
                        ManageCustomer.UpdateCustomerBasicInfo(new Guid(base.Request.QueryString["CustomerId"]), strName, strGender, strTitle, iLevel, companyId, strDepart, new Guid(this.catDdl.SelectedValue), new Guid(this.regionDdl.SelectedValue), productId, this.TypeDdl.SelectedValue, strEmailTxb, strMailAddTxb);
                        this.Page.Session.Add("CustomerId", new Guid(base.Request.QueryString["CustomerId"]));
                        this.lbSaveMsg.Text = "Save Successfully!";
                        this.lbSureMsg.Text = "";
                        ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "UpDateBasic", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, ManageCustomer.GetCustomerBasicInfoViaId(new Guid(base.Request.QueryString["CustomerId"])).Name, new Guid(base.Request.QueryString["CustomerId"]));
                        string strIP = base.Request.UserHostAddress;
                    }
                    else if (((string) this.Page.Session["IsModify"]) == "True")
                    {
                        ManageCustomer.UpdateCustomerBasicInfo((Guid) this.Page.Session["CustomerId"], strName, strGender, strTitle, iLevel, companyId, strDepart, new Guid(this.catDdl.SelectedValue), new Guid(this.regionDdl.SelectedValue), productId, this.TypeDdl.SelectedValue, strEmailTxb, strMailAddTxb);
                        this.lbSaveMsg.Text = "Save Successfully!";
                        this.lbSureMsg.Text = "";
                        ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "UpDateBasic", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, ManageCustomer.GetCustomerBasicInfoViaId((Guid) this.Page.Session["CustomerId"]).Name, (Guid) this.Page.Session["CustomerId"]);
                    }
                    else if (ManageCustomer.IsExistSameCoustomer(strName, strGender))
                    {
                        this.lbSureMsg.Text = "已存在名为" + strName + "的客户是否继续保存该用户？";
                        this.saveBtn.Visible = false;
                        this.sureSaveBtn.Visible = true;
                        this.cancelSaveBtn.Visible = true;
                    }
                    else
                    {
                        Guid customerId = Guid.NewGuid();
                        ManageCustomer.InsertNewCustomerBasicInfo(customerId, strName, strGender, strTitle, iLevel, companyId, strDepart, new Guid(this.catDdl.SelectedValue), new Guid(this.regionDdl.SelectedValue), this.Principal.OwnArea[0].AreaId, this.Principal.SysUser.UserId, productId, this.TypeDdl.SelectedValue, strEmailTxb, strMailAddTxb);
                        this.Page.Session.Add("CustomerId", customerId);
                        this.Page.Session["IsModify"] = "True";
                        this.lbSaveMsg.Text = "Save Successfully!";
                        this.lbSureMsg.Text = "";
                        ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "InsertBasic", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, ManageCustomer.GetCustomerBasicInfoViaId(customerId).Name);
                    }
                }
            }
            catch (Exception ex)
            {
                this.lbSaveMsg.Text = ex.Message;
            }
        }

        private void SelectAuth()
        {
            if (this.Principal.OwnRole.TypeB == 0)
            {
                this.InitPage();
                this.FillPage();
                this.customerNameTxb.ReadOnly = true;
                this.titleTxb.ReadOnly = true;
                this.departTxb.ReadOnly = true;
                this.saveBtn.Visible = false;
                this.TypeAddBtn.Visible = false;
                this.DelBtn.Visible = false;
                this.ProductDdl.Visible = false;
            }
            else if (this.Principal.OwnRole.TypeB == 1)
            {
                this.InitPage();
                this.FillPage();
            }
        }

        private void SetFrom()
        {
            string language = this.Session["language"].ToString();
            string path = base.Server.MapPath("~/CIS/LanguageConfig.xml");
            this.lbCustomerName.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbCustomerName", language, path);
            this.lbGender.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbGender", language, path);
            this.lbTitle.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbTitle", language, path);
            this.lbStrLevel2.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbStrLevel2", language, path);
            this.lbLevel.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbLevel", language, path);
            this.lbStrLevel1.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbStrLevel1", language, path);
            this.RequiredFieldValidatorName.ErrorMessage = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "RequiredFieldValidatorName", language, path);
            this.lbStrLevel3.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbStrLevel3", language, path);
            this.lbStrLevel4.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbStrLevel4", language, path);
            this.lbStrLevel5.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbStrLevel5", language, path);
            this.lbCompany.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbCompany", language, path);
            this.lbDepart.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbDepart", language, path);
            this.saveBtn.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "saveBtn", language, path);
            this.sureSaveBtn.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "sureSaveBtn", language, path);
            this.cancelSaveBtn.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "cancelSaveBtn", language, path);
            this.TypeAddBtn.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "TypeAddBtn", language, path);
            this.DelBtn.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "DelBtn", language, path);
            this.lbProduct.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbProduct", language, path);
            this.lbType.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbType", language, path);
            this.lbMail.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbMail", language, path);
            this.lbMailAdd.Text = ManageSystemConfig.GetSystemSetLanguage("CustomerBasicInfoPage", "lbMailAdd", language, path);
        }

        private void SetFromImage()
        {
            switch (this.Session["language"].ToString())
            {
                case "cn":
                    this.iBtnCustomer.ImageUrl = "../images/title_customerinfo.jpg";
                    this.iBtnGray0.ImageUrl = "../images/title_CustomerInfo_lable_1_Gray.jpg";
                    this.iBtnOrange1.ImageUrl = "../images/title_CustomerInfo_lable_2_orange.jpg";
                    this.iBtnOrange2.ImageUrl = "../images/title_CustomerInfo_lable_3_orange.jpg";
                    this.iBtnOrange3.ImageUrl = "../images/title_CustomerInfo_lable_4_orange.jpg";
                    this.iBtnOrange4.ImageUrl = "../images/title_CustomerInfo_lable_5_orange.jpg";
                    this.iBtnOrange5.ImageUrl = "../images/title_CustomerInfo_lable_6_orange.jpg";
                    this.iBtnOrange6.ImageUrl = "../images/title_CustomerInfo_lable_7_orange.jpg";
                    this.iBtnOrange7.ImageUrl = "../images/title_CustomerInfo_lable_8_orange.jpg";
                    this.iBtnOrange8.ImageUrl = "../images/title_CustomerInfo_lable_9_orange.gif";
                    break;

                case "en":
                    this.iBtnCustomer.ImageUrl = "../images/title_customerinfoEn.jpg";
                    this.iBtnGray0.ImageUrl = "../images/title_CustomerInfoEn_lable_1_Gray.jpg";
                    this.iBtnOrange1.ImageUrl = "../images/title_CustomerInfoEn_lable_2_orange.jpg";
                    this.iBtnOrange2.ImageUrl = "../images/title_CustomerInfoEn_lable_3_orange.jpg";
                    this.iBtnOrange3.ImageUrl = "../images/title_CustomerInfoEn_lable_4_orange.jpg";
                    this.iBtnOrange4.ImageUrl = "../images/title_CustomerInfoEn_lable_5_orange.jpg";
                    this.iBtnOrange5.ImageUrl = "../images/title_CustomerInfoEn_lable_6_orange.jpg";
                    this.iBtnOrange6.ImageUrl = "../images/title_CustomerInfoEn_lable_7_orange.jpg";
                    this.iBtnOrange7.ImageUrl = "../images/title_CustomerInfoEn_lable_8_orange.jpg";
                    this.iBtnOrange8.ImageUrl = "../images/title_CustomerInfoEn_lable_9_orange.gif";
                    break;
            }
        }

        private void SetInfoTypeDdl(DropDownList tepDDL, string strValue)
        {
            for (int i = 0; i < tepDDL.Items.Count; i++)
            {
                if (tepDDL.Items[i].Value == strValue)
                {
                    tepDDL.SelectedIndex = i;
                    break;
                }
            }
        }

        private void sureSaveBtn_Click(object sender, EventArgs e)
        {
            if (!this.ValidateCustomerCompany(new Guid(this.companyDdl.SelectedValue), new Guid(this.regionDdl.SelectedValue), new Guid(this.catDdl.SelectedValue)))
            {
                this.lbSaveMsg.Text = "";
                this.lbSureMsg.Text = "客户公司和所设区域不符！";
            }
            else
            {
                string strEmailTxb = this.EmailTxb.Text.Trim();
                string strMailAddTxb = this.MailAddTxb.Text.Trim();
                string strName = this.customerNameTxb.Text.Trim();
                string strGender = this.genderDdl.SelectedItem.Text;
                string strTitle = this.titleTxb.Text.Trim();
                int iLevel = Convert.ToInt32(this.levelDdl.SelectedItem.Value);
                Guid companyId = new Guid(this.companyDdl.SelectedItem.Value);
                string strDepart = this.departTxb.Text.Trim();
                Guid[] productId = new Guid[this.ProductLB.Items.Count];
                for (int i = 0; i < this.ProductLB.Items.Count; i++)
                {
                    productId[i] = new Guid(this.ProductLB.Items[i].Value);
                }
                Guid customerId = Guid.NewGuid();
                ManageCustomer.InsertNewCustomerBasicInfo(customerId, strName, strGender, strTitle, iLevel, companyId, strDepart, new Guid(this.catDdl.SelectedValue), new Guid(this.regionDdl.SelectedValue), this.Principal.OwnArea[0].AreaId, this.Principal.SysUser.UserId, productId, this.TypeDdl.SelectedValue, strEmailTxb, strMailAddTxb);
                this.saveBtn.Visible = true;
                this.sureSaveBtn.Visible = false;
                this.cancelSaveBtn.Visible = false;
                this.Page.Session.Add("CustomerId", customerId);
                this.lbSaveMsg.Text = "Save successfully!";
                this.lbSureMsg.Text = "";
                ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "InsertBasic", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, ManageCustomer.GetCustomerBasicInfoViaId(customerId).Name);
            }
        }

        private void TypeAddBtn_Click(object sender, EventArgs e)
        {
            ListItem tmpItem = new ListItem();
            tmpItem.Text = this.ProductDdl.SelectedItem.Text;
            tmpItem.Value = this.ProductDdl.SelectedItem.Value;
            if (!this.IsExistItem(tmpItem, this.ProductLB))
            {
                this.ProductLB.Items.Add(tmpItem);
            }
        }

        private bool ValidateCustomerCompany(Guid CompanyId, Guid regionId, Guid catId)
        {
            Company company = new Company();
            company = ManageCompany.GetCompanyViaId(CompanyId);
            return (company.RegionId.Equals(regionId) && company.CATtId.Equals(catId));
        }
    }
}

